﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.ServiceModel.Activation;
using AgileNYCWebService.Manager.Data;
using AgileNYCWebService.Manager.Data.Table;
using System.Web;

namespace AgileNYCWebService
{
	// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
	// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.

	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
	public class AgileUsers : IAgileUsers
	{
		public JsonResult Login(Users user)
		{
			if (user != null)
			{
				return new DataManager().Login(user);
			}
			return new JsonResult() { Error = "Posted data is null", Result = string.Empty };
		}

		public JsonResult UploadPhoto(string userToken, Stream fileContents)
		{
			return new DataManager(userToken).Photo(fileContents);
		}

		public string GetUserDetails(string userToken)
		{
			JsonResult result = new DataManager(userToken).GetUserDetails();
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;
			return result.Error;
		}

		public JsonResult SaveUserDetails(Users userDetails)
		{
			if (userDetails != null)
			{
				return new DataManager(userDetails.UserToken).SaveUserDetails(userDetails);
			}
			return new JsonResult() { Error = "Posted data is null", Result = string.Empty };
		}

		public string SendNotification(string userToken, int code)
		{
			JsonResult result = new DataManager(userToken).SendNotification(code);
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;

			return result.Error;
		}

		public void ReplyNotification(string userToken, int code, bool agree)
		{
			if (!string.IsNullOrEmpty(userToken) && code > 999 && code < 10000)
			{
				new DataManager(userToken).ReplyNotification(code, agree);
			}
		}

		public string CheckNotification(string userToken)
		{
			JsonResult result = new DataManager(userToken).CheckNotification();
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;

			return result.Error;
		}

        public string CheckEmail(string email)
        {
            JsonResult result = new DataManager().CheckEmail(email);
            if (string.IsNullOrEmpty(result.Error))
                return result.Result;

            return result.Error;
        }


		public string Contacts(string userToken, int offset, int limit)
		{
			JsonResult result = new DataManager(userToken).Contacts(offset, limit);
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;

			return result.Error;
		}

		public JsonResult AddNote(Note noteData)
		{
			if (noteData != null)
			{
				return new DataManager(noteData.UserToken).AddNote(noteData);
			}
			return new JsonResult() { Error = "Posted data is null", Result = string.Empty };
		}

		public JsonResult DeleteNote(Note note)
		{
			if (note != null)
			{
				return new DataManager(note.UserToken).DeleteNote(note);
			}
			return new JsonResult() { Error = "Posted data is null", Result = string.Empty };
		}


		public string DeletePhoto(string userToken)
		{
			JsonResult result = new DataManager(userToken).DeletePhoto();
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;

			return result.Error;
		}


		public string DeleteContact(string userToken, int code)
		{
			JsonResult result = new DataManager(userToken).DeleteContact(code);
			if (string.IsNullOrEmpty(result.Error))
				return result.Result;

			return result.Error;
		}
	}
}
